import { checkPassWord, checkUserName } from "@/check.js"
import './index.css'
import './index.less'
import Logo from './assets/logo.png'
import axios from "axios"
document.querySelector('.logo-img').src = Logo

const button = document.querySelector('button')
button.addEventListener('click', () => {
  // 获得输入框的值
  const usernameVal = document.querySelector('.username').value
  const passwordVal = document.querySelector('.password').value
  if (checkUserName(usernameVal) === false) {
    alert('用户名不合法,长度必须超过6位')
    return
  }

  if (checkPassWord(passwordVal) === false) {
    alert('密码不合法,长度必须超过8位')
    return
  }
  axios.post('https://hmajax.itheima.net/api/register', {
    username: usernameVal,
    password: passwordVal
  }).then(res => {
    console.log(res.data.data.id)
    alert(`注册成功,用户id为:${res.data.data.id}`)
  }).catch(err => {
    console.log(err)
    alert(`注册失败,${err.response.data.message}`)
  })
})

const username = 'itheima'
console.log(username)
console.log(`用户名为:${username}`)
const arr = [1, 2, 3, 4, 5]
const res = arr.map((item) => item * 2)
console.log(res)
console.log(res11111111)

